﻿Imports TodoMicroSolutionPackV1.dal.dto
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
Imports Iesi.Collections.Generic
Imports NHibernate
Imports NHibernate.Cfg
Imports NHibernate.Criterion

Namespace productos.dal.dto
    Public Class producto
        Private _id As Integer
        Private _codigo As String
        Private _descripcion As String
        Private _iva As constante
        Private _unidad_medida As constante
        Private _stocks As IList(Of stock) = New List(Of stock)
        Private _precios As IList(Of precio) = New List(Of precio)

        <DisplayName("ID")>
        <Display(Order:=0, name:="ID")>
        Public Overridable Property id As Integer
            Get
                Return _id
            End Get
            Set(ByVal value As Integer)
                _id = value
            End Set
        End Property
        <DisplayName("Codigo")>
        <Display(Order:=1, Name:="Codigo")>
        Public Overridable Property codigo As String
            Get
                Return _codigo
            End Get
            Set(ByVal value As String)
                _codigo = value
            End Set
        End Property
        <DisplayName("Descripcion")>
        <Display(Order:=2, Name:="Descripcion")>
        Public Overridable Property descripcion As String
            Get
                Return _descripcion
            End Get
            Set(ByVal value As String)
                _descripcion = value
            End Set
        End Property
        <Browsable(False)>
        Public Overridable Property iva As constante
            Get
                Return _iva
            End Get
            Set(ByVal value As constante)
                _iva = value
            End Set
        End Property
        <DisplayName("IVA")>
        <Display(Order:=3, Name:="IVA")>
        Public Overridable ReadOnly Property iva_valor As Double
            Get
                Return CDbl(_iva.valor)
            End Get
        End Property
        Private ReadOnly Property ivaConstantIsOK As Boolean
            Get
                Return _iva Is Nothing OrElse constantsUtil.isAlicuotaIva(_iva)
            End Get
        End Property
        <Browsable(False)>
        Public Overridable Property unidad_medida As constante
            Get
                Return _unidad_medida
            End Get
            Set(ByVal value As constante)
                _unidad_medida = value
            End Set
        End Property
        <DisplayName("Unidad de Medida")>
        <Display(Order:=4, Name:="Unidad de Medida")>
        Public Overridable ReadOnly Property unidad_medida_valor As String
            Get
                Return _unidad_medida.valor
            End Get
        End Property
        Private ReadOnly Property unidadMedidaConstantIsOK As Boolean
            Get
                Return _unidad_medida Is Nothing OrElse constantsUtil.isUnidadMedida(_unidad_medida)
            End Get
        End Property
        <Browsable(False)>
        Public Overridable Property stocks As IList(Of stock)
            Get
                Return _stocks
            End Get
            Set(ByVal value As IList(Of stock))
                _stocks = value
            End Set
        End Property
        <Browsable(False)>
        Public Overridable Property precios As IList(Of precio)
            Get
                Return _precios
            End Get
            Set(ByVal value As IList(Of precio))
                _precios = value
            End Set
        End Property
        Public Overridable Sub addStock(ByRef theStock As stock)
            theStock.producto = Me
            _stocks.Add(theStock)
        End Sub
        Public Overridable Sub addPrecio(ByRef thePrecio As precio)
            thePrecio.producto = Me
            _precios.Add(thePrecio)
        End Sub
        Public Overridable Function getPrecioPorlista(ByVal lista As Integer) As precio
            Return _precios.OfType(Of precio).Where(Function(precio) precio.lista_id.Equals(lista)).OrderBy(Function(precio) precio.fecha).ElementAt(0)
        End Function
    End Class
End Namespace